package com.coco.homework;

import java.util.ArrayList;
import java.util.List;

public class Context {

	private String base;
	
	public static final char EOF_CHAR = '&';

	private int currentIndex;

	private List<Integer> tokenVals = new ArrayList<>();

	public Context(String base) {
		this.base = base;
	}

	public boolean eof() {
		return currentIndex >= base.length();
	}
	
	public String getLeftString() {
		return base.substring(currentIndex);
	}
	
	public void skipCharCount(int count) {
		currentIndex += count;
	}

	public char getCurrentChar() {
		return base.charAt(currentIndex);
	}
	
	public char getNextChar() {
		if (currentIndex < base.length() -1) {
			return base.charAt(++currentIndex);
		}
		return EOF_CHAR;
	}

	public Integer getValue() {
		return this.tokenVals.stream().reduce(0, Integer::sum);
	}

	public void addTokenVal(Integer tokenVal) {
		if (null != tokenVal) {
			this.tokenVals.add(tokenVal);
		}
	}
}
